﻿<script language ="javascript" type="text/javascript" >
 <!--
  //四舍五入
   function JsRound(a_Num , a_Bit)
  {
       return((Math.round(a_Num * Math.pow (10,a_Bit+8)) / Math.pow(10,a_Bit+8)).toFixed(a_Bit)); 
  }
             
      var   X   =   0;   
      var   Y   =   0;   
      var   rowLen   =   0;   
      var   cellLen   =   0;   
      function   init()   
      {  
      //debugger; 
          //tbl1.rows[0].cells[1].all[0].focus();   
          X   =   0;   
          Y   =   1;   
          rowLen   =   tbl1.rows.length   -   1;   
          cellLen   =   tbl1.rows[0].cells.length   -   1;   
      }   
      //document.onkeydown   =   keyDown;   
      function   keyDown()   
      {     
              //debugger;
              var   keycode   =   event.keyCode;   
              if   (  keycode   ==   37      ||   keycode   ==   38     ||   keycode   ==   39 ||   keycode   ==   40 )   
              {   
                      if   (   keycode   ==   37   )   
                      {   
                              if   (Y   >   0)   
                              {   
                                      Y=Y-2; 
                              }   
                              changeActiveObj(X,   Y);   
                      }   
                      if   (   keycode   ==   38   )   
                      {   
                              if   (X   >   0)   
                              {   
                                      X=X-1; 
                              }   
                              changeActiveObj(X,   Y);   
                      }   
                      if   (   keycode   ==   39   )   
                      {   
                              if   (Y   <   cellLen)   
                              {   
                                      Y=Y+2; 
                              }                           
                              changeActiveObj(X,   Y);   
                      }   
                      if   (   keycode   ==   40   )   
                      {   
                              if   (X   <   rowLen)   
                              {   
                                      X=X+1;  
                              }   
                              changeActiveObj(X,   Y);   
                      }   
              }   
      }   
      function   changeActiveObj(X,   Y)   
      {   
              //debugger;
              if(tbl1.rows[X].cells.length<=Y)
              {
                var cell=tbl1.rows[X].cells.length-1;
                eval("tbl1.rows["   +   X   +   "].cells["   +   cell   +   "].all[0]").focus(); 
              }
              else
              {
                eval("tbl1.rows["   +   X   +   "].cells["   +   Y   +   "].all[0]").focus(); 
              }  
      } 
   
    function searchObjByTagName(obj, tag)
    {
        //debugger;
        while(obj!=null && typeof(obj.tagName)!="undefind")
        {
            if(obj.tagName==tag.toUpperCase()) return(obj);
            obj=obj.parentElement; 
        } return null;
    }
    
    function change(obj)
    {
        //debugger;
        var inputs = document.getElementById("tbl1").getElementsByTagName("INPUT");
        for(var i=0; i<inputs.length; i++)
        {
            var td = searchObjByTagName(inputs[i], "TD");
            var tr = td.parentNode;
            if(inputs[i].id==obj.id)
            {
                X=tr.rowIndex;
                Y=td.cellIndex;
            }
        }
    }

 -->
 </script>